﻿Imports Capa_de_Acceso_a_Datos

Public Class frmConsultarCobros

    Private Sub frmConsultarCobros_FormClosed(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosedEventArgs) Handles Me.FormClosed
        Me.Dispose()
    End Sub


    Private Sub ConsultarCobros_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        CargarCombos()
        CargarGrilla()

        With dgvCobros
            ' alternar color de filas  
            .AlternatingRowsDefaultCellStyle.BackColor = Color.FloralWhite
            .DefaultCellStyle.BackColor = Color.Beige
        End With
    End Sub

    Private Sub CargarCombos()
        'Combo Año
        cboAno.ValueMember = "AnoId"
        cboAno.DisplayMember = "Ano"
        cboAno.DataSource = Constante.obtenerAnos

        'Combo Mes 
        cboMes.ValueMember = "MesId"
        cboMes.DisplayMember = "Descripcion"
        cboMes.DataSource = MesDAO.comboFiltroMes
        'cboMesNC.SelectedValue = Date.Now.Month

        'Combo ObraSocialXPlan
        cboObraSocial.ValueMember = "ObraSocialXPlanId"
        cboObraSocial.DisplayMember = "Descripcion"
        cboObraSocial.DataSource = ObraSocialXPlanDAO.comboFiltroObraSocialXPlan

    End Sub

    Private Sub CargarGrilla()
        Try
            dgvCobros.DataSource = CobroDAO.obtenerCobrosXFiltro(cboObraSocial.SelectedValue, cboMes.SelectedValue, cboAno.SelectedValue)
        Catch ex As Exception
            MsgBox(ex.Message.ToString)
        End Try
    End Sub

    Private Sub btnSalir_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSalir.Click
        Me.Dispose()
    End Sub

    Private Sub btnFiltrar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnFiltrar.Click
        CargarGrilla()
    End Sub


    Private Sub btnVisualizar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnVisualizar.Click
        Dim CobroFecha As Date
        Dim Descripcion As String

        If HayFilaSeleccionada() Then
            CobroFecha = dgvCobros.SelectedRows(0).Cells("CobroFecha").Value
            Descripcion = dgvCobros.SelectedRows(0).Cells("Descripcion").Value

            frmConsultarDetallesCobro.Titulo = CobroFecha.ToString & " - " & Descripcion
            frmConsultarDetallesCobro.ShowDialog()
        Else
            MsgBox("Debe seleccionar un cobro para visualizarlo.", MsgBoxStyle.Exclamation)
        End If

    End Sub

    Private Function HayFilaSeleccionada() As Boolean
        Dim hay As Boolean = False

        If dgvCobros.SelectedRows.Count > 0 Then
            hay = True
        End If

        Return hay
    End Function
End Class